package com.ruoyi.web.controller.material;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.material.domain.WarehouseOutProduct;
import com.ruoyi.material.service.IWarehouseOutProductService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单商品关联Controller
 *
 * @author wng
 * @date 2024-08-04
 */
@RestController
@RequestMapping("/material/warehouseOutProduct")
public class WarehouseOutProductController extends BaseController {
    @Resource
    private IWarehouseOutProductService warehouseOutProductService;

    /**
     * 查询出库单商品关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseOutProduct warehouseOutProduct) {
        startPage();
        List<WarehouseOutProduct> list = warehouseOutProductService.selectWarehouseOutProductList(warehouseOutProduct);
        return getDataTable(list);
    }

    /**
     * 导出出库单商品关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:export')")
    @Log(title = "出库单商品关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseOutProduct warehouseOutProduct) {
        List<WarehouseOutProduct> list = warehouseOutProductService.selectWarehouseOutProductList(warehouseOutProduct);
        ExcelUtil<WarehouseOutProduct> util = new ExcelUtil<WarehouseOutProduct>(WarehouseOutProduct.class);
        util.exportExcel(response, list, "出库单商品关联数据");
    }

    /**
     * 获取出库单商品关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(warehouseOutProductService.selectWarehouseOutProductById(id));
    }

    /**
     * 新增出库单商品关联
     */
    @PreAuthorize("@ss.hasPermi('system:product:add')")
    @Log(title = "出库单商品关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseOutProduct warehouseOutProduct) {
        return toAjax(warehouseOutProductService.insertWarehouseOutProduct(warehouseOutProduct));
    }

    /**
     * 修改出库单商品关联
     */
    @PreAuthorize("@ss.hasPermi('system:product:edit')")
    @Log(title = "出库单商品关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseOutProduct warehouseOutProduct) {
        return toAjax(warehouseOutProductService.updateWarehouseOutProduct(warehouseOutProduct));
    }

    /**
     * 删除出库单商品关联
     */
    @PreAuthorize("@ss.hasPermi('system:product:remove')")
    @Log(title = "出库单商品关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(warehouseOutProductService.deleteWarehouseOutProductByIds(ids));
    }
}
